package com.chenglu.android.common.utils;


import android.content.Context;

import com.chenglu.android.R;
import com.chenglu.android.common.base.Global;
import com.lxj.xpopup.XPopup;
import com.lxj.xpopup.core.BasePopupView;
import com.lxj.xpopup.interfaces.OnCancelListener;
import com.lxj.xpopup.interfaces.OnConfirmListener;

/**
 * com.huahan.goldbg.util
 *
 * @author HuaHan008 - YangCheng
 * Date：2022/11/9
 * Time：15:50
 * Content：通用的弹窗工具类
 */
public class BaseDialog {
    private static BasePopupView basePopupView;
    //通用的提示类型弹窗

    /**
     * @param content 提示内容
     */
//    public static void showImageDialog(Context context ,String content) {
//        new XPopup.Builder(context)
//                .asConfirm("温馨提示", content, "取消", "确定",null, null, true, R.layout.item_popupwindow_dialog_image)
//                .show();
//    }

    /**
     * @param content 提示内容
     */
    public static void showDialog(Context context ,String content) {
        new XPopup.Builder(context)
                .dismissOnTouchOutside(true)
                .dismissOnBackPressed(true)
                .asConfirm("温馨提示", content, "取消", "确定", null, null, true, R.layout.item_popupwindow_dialog)
                .show();
    }

    /**
     * @param content           提示内容
     * @param onConfirmListener 确定按钮回调
     */
    public static void showDialog( Context context ,boolean isCancelable, String content, OnConfirmListener onConfirmListener) {
        new XPopup.Builder(context)
                .dismissOnTouchOutside(isCancelable)
                .dismissOnBackPressed(isCancelable)
                .asConfirm("温馨提示", content, "取消", "确定", onConfirmListener, null, true, R.layout.item_popupwindow_dialog)
                .show();
    }

    public static void showDialog(Context context ,String content, String cancelBtnText, String confirmBtnText,
                                  OnConfirmListener confirmListener, boolean isHideCancel) {
        new XPopup.Builder(context)
                .asConfirm("温馨提示", content, cancelBtnText, confirmBtnText, confirmListener, null, isHideCancel, R.layout.item_popupwindow_dialog)
                .show();
    }

    public static void showDialog(Context context ,String content, String cancelBtnText, String confirmBtnText,
                                  OnConfirmListener confirmListener, OnCancelListener cancelListener, boolean isHideCancel) {
        new XPopup.Builder(context)
                .asConfirm("温馨提示", content, cancelBtnText, confirmBtnText, confirmListener, cancelListener, isHideCancel, R.layout.item_popupwindow_dialog)
                .show();
    }

    /**
     * 全自定义弹出窗
     *
     * @param isCancelable    弹出窗是否可取消
     * @param title           对话框标题，传空串会隐藏标题
     * @param content         对话框内容
     * @param cancelBtnText   取消按钮的文字内容
     * @param confirmBtnText  确认按钮的文字内容
     * @param confirmListener 点击确认的监听器
     * @param cancelListener  点击取消的监听器
     * @param isHideCancel    是否隐藏取消按钮
     * @return
     */
    public static void showDialog(Context context ,boolean isCancelable, String title, String content, String cancelBtnText, String confirmBtnText,
                                  OnConfirmListener confirmListener, OnCancelListener cancelListener, boolean isHideCancel) {
        new XPopup.Builder(context)
                .dismissOnTouchOutside(isCancelable)
                .dismissOnBackPressed(isCancelable)
                .asConfirm(title, content, cancelBtnText, confirmBtnText, confirmListener, cancelListener, isHideCancel, R.layout.item_popupwindow_dialog)
                .show();
    }

    /**
     * 全自定义弹出窗
     *
     * @param isCancelable    弹出窗是否可取消
     * @param title           对话框标题，传空串会隐藏标题
     * @param content         对话框内容
     * @param cancelBtnText   取消按钮的文字内容
     * @param confirmBtnText  确认按钮的文字内容
     * @param confirmListener 点击确认的监听器
     * @param cancelListener  点击取消的监听器
     * @param isHideCancel    是否隐藏取消按钮
     * @return
     */
    public static void showBaseDialog(Context context ,boolean isCancelable, boolean autoDismiss, String title, String content, String cancelBtnText, String confirmBtnText,
                                  OnConfirmListener confirmListener, OnCancelListener cancelListener, boolean isHideCancel) {
        basePopupView = new XPopup.Builder(context)
                .dismissOnTouchOutside(isCancelable)
                .dismissOnBackPressed(isCancelable)
                .autoDismiss(autoDismiss)
                .asConfirm(title, content, cancelBtnText, confirmBtnText, confirmListener, cancelListener, isHideCancel, R.layout.item_popupwindow_dialog)
                .show();
    }

    public static void dismissDialog() {
        if (basePopupView != null) {
            basePopupView.smartDismiss();
        }
    }
}
